home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / WEBSERVER.TXT < prev    next >
Encoding:
Text File  |  2000-10-30  |  18.3 KB  |  461 lines

  1. Using Zope with an existing web server
  2. --------------------------------------
  3.  
  4.   While Zope comes with a web server, you may wish to use it with an
  5.   existing web server.  Use Persistent CGI (PCGI) or FastCGI to allow
  6.   your existing web server to work with Zope on Unix and Windows.
  7.  
  8.   Roughly, PCGI is a protocol for translating CGI requests from a web
  9.   server into Zope requests.  CGI requests are traditionally one shot
  10.   events; the web server handles a request for a CGI script by
  11.   spawning a new process to handle the requests, returning the results
  12.   of the request when the process dies.
  13.  
  14.   Zope is a long running process, which means that it does not start
  15.   up and die on each request like traditional CGI programs.  If it
  16.   did, each request would take far too long due to the time to start
  17.   and stop an application server like Zope.  Thus, PCGI is one of the
  18.   options for gatewaying from the separate CGI processes to the Zope
  19.   long running process.
  20.  
  21.   FastCGI is very similar to PCGI.  Where PCGI has a "wafer-thin"
  22.   external CGI program to connect Apache and Zope, FastCGI has an
  23.   Apache module.  This saves the so called "fork tax" which is incurred
  24.   when Apache forks to execute the PCGI CGI program.
  25.  
  26.  
  27. Using Zope in multi-threaded mode with ZServer
  28. ----------------------------------------------
  29.  
  30.   ZServer is a general purpose TCP server for publishing Zope objects
  31.   over various transport protocols.  For Zope to run multi-threaded,
  32.   you must run ZServer.
  33.  
  34.   ZServer is based on Sam Rushing's Medusa software.  The benefit of
  35.   using Medusa as the ZServer core is that it is not protocol specific
  36.   (Medusa provides libraries to program for any protocol) and it is
  37.   easily extensible.  Because Medusa is written in Python, is
  38.   extremely high performance by design, and comes with an HTTP and FTP
  39.   server, we chose it for the Zope core.
  40.  
  41.   It is not necessary, however, for ZServer to actually listen for
  42.   incoming HTTP requests.  If you want Apache to do the actual
  43.   listening and serving, then you can use ZServer's PCGI or FastCGI
  44.   components to communicate with Apache.
  45.  
  46.  PCGI
  47.  
  48.   To run ZServer with PCGI, you must specify the -p option to the
  49.   'z2.py' startup script.  From the top level Zope directory, you
  50.   can::
  51.  
  52.     bash% python1.5.2 z2.py -p
  53.  
  54.   Note, you must have gone through the directions in 'INSTALL.txt' for
  55.   this to work.
  56.  
  57.   This command will start ZServer up with PCGI (by default, it will
  58.   also start up an HTTP and FTP server).  For PCGI to work, the
  59.   webserver and Zope must agree on a PCGI resource file.  If this file
  60.   is not named 'Zope.cgi' and is not in the same directory as 'z2.py',
  61.   then you can specify the file name after the '-p', like::
  62.  
  63.     bash% python.1.5.2 z2.py -p /path/to/PCGI/resource/file
  64.  
  65.   Now the Zope long running process is started up, and the PCGI
  66.   component is loaded and ready to receive CGI requests from your
  67.   webserver.  
  68.  
  69.   The installation process should create a 'Zope.cgi' PCGI file. Copy
  70.   the 'Zope.cgi' file to your web server's 'cgi-bin' directory.
  71.   
  72.   On Unix you can also create a symbolic link to 'Zope.cgi' from your
  73.   cgi-bin directory. For example::
  74.  
  75.     ln -s /home/amos/Zope/Zope.cgi /usr/local/apache/cgi-bin/Zope
  76.  
  77.   At this point you should perform any other steps you web server
  78.   requires to install and configure a CGI script.
  79.  
  80.   Note: For more information on PCGI check out Jeff Bauer's "PCGI pages", 
  81.   http://starship.skyport.net/crew/jbauer/persistcgi/.
  82.  
  83.   When your Zope.cgi file is correctly configured as a CGI script with
  84.   your web server, you are ready to access Zope through the web. You
  85.   should point your browser at:
  86.  
  87.     'http://youmachine.example.com:8998/cgi-bin/Zope.cgi/manage'
  88.  
  89.   (Your URL maybe be different depending on how your web server is configured.)
  90.  
  91.   You should be prompted to enter a username and password.  Enter the
  92.   Zope "super manager" name and password.
  93.  
  94.   Note: Apache requires some tricky configuration to get it to pass
  95.   the HTTP authentication header information to Zope.  See the section 
  96.   'Zope authentication with existing web servers'.
  97.  
  98.  FastCGI
  99.  
  100.   FastCGI is relatively easy to set up if you have installed an Apache
  101.   module before.  If you haven't, don't worry, it isn't difficult.  It
  102.   comes with straightforward instructions.  You will need to download
  103.   the mod_fastcgi module from FastCGI.com:
  104.  
  105.     http://www.fastcgi.com
  106.  
  107.   A version more recent than 2.2.2 is needed.  If 2.2.3 or greater is
  108.   not yet available, get one of the snapshots from October 6th or
  109.   later:
  110.  
  111.     http://www.fastcgi.com/dist/
  112.  
  113.   Extract the archive and follow the directions in its 'INSTALL' file.
  114.   Using the 'DSO' method is usually easiest.
  115.  
  116.   Next, Zope must be set up to use FastCGI.  You must decide whether
  117.   you want to use FastCGI via a Unix domain socket or a TCP port.
  118.  
  119.   You will have to use a TCP port if you are using a Win32 box, or any
  120.   other operating system that does not provide Unix domain sockets
  121.   (sockets in the filesystem).  It is also the method you must use if
  122.   Apache and Zope reside on different computers.  You will need to
  123.   select a port number.  This is arbitrary, but it must not already be
  124.   in use, and if you are not the super-user, it must be a sufficiently
  125.   high number.  For illustrative purposes, I will use 8889.
  126.  
  127.   Unix domain sockets do not open a TCP port, which may be significant
  128.   in some tight-security situation, but it requires slightly more
  129.   setup, and so it is slightly less fool-proof.  You will need to
  130.   select a location and filename for the socket.  Likely options are
  131.   '/tmp/zope.soc' or within Zope's 'var' directory.  Make sure that
  132.   both Zope and Apache will have adequate file permissions to read and
  133.   write to the socket.  For illustrative purposes, I will use
  134.   '/tmp/zope.soc'.
  135.  
  136.   The option to configure this is '-F (port #|socket filename)'.  Edit
  137.   your 'start' script.  It's found in the root of your Zope
  138.   installation, and it will look something like this::
  139.  
  140. #! /bin/sh
  141. reldir=`dirname $0`
  142. PYTHONHOME=`cd $reldir; pwd`
  143. export PYTHONHOME
  144. exec /usr/bin/python \
  145.      $PYTHONHOME/z2.py \
  146.      -D "$@"
  147.  
  148.   Insert a line before after '$PYTHONHOME/z2.py \'.  If you are using
  149.   a TCP port, it will look like this::
  150.  
  151.      -F 8889 \
  152.  
  153.   If you are using a socket, the line will look like this::
  154.  
  155.      -F /tmp/zope.soc \
  156.  
  157.   The trailing backslash is significant!  You can start Zope at this
  158.   point by running the 'start' script::
  159.  
  160. $ ./start
  161.  
  162.   Note that by default the start script starts Zope in debug mode, and
  163.   so this command will not come back to a shell prompt until Zope
  164.   exits.
  165.  
  166.   Next, Apache must be set up to pass FastCGI requests to Zope.  This
  167.   is done with a 'FastCgiExternalServer' directive in Apache's
  168.   httpd.conf.  By using 'FastCgiExternalServer' we are telling FastCGI
  169.   that we'll be launching and killing the long-running process
  170.   manually.  It goes at the beginning of 'Section 2'.  This directive
  171.   will look like this for a TCP port configuration::
  172.  
  173. FastCgiExternalServer /PATH/TO/apache/htdocs/zope \
  174.                       -host localhost:8889        \
  175.                       -pass-header Authorization
  176.  
  177.   ...or like this for a socket configuration::
  178.  
  179. FastCgiIpcDir /tmp
  180. FastCgiExternalServer /PATH/TO/apache/htdocs/zope \
  181.                       -socket zope.soc            \
  182.                       -pass-header Authorization
  183.  
  184.   The FastCgiIpcDir directive is needed to tell FastCGI where to find
  185.   the socket file.  By default, FastCGI will look in /tmp/fcgi.  You
  186.   *cannot* specify a full path with the '-socket' option, only a
  187.   filename within the FastCgiIpcDir.
  188.  
  189.   The first argument after the directive name is confusing.  Apache
  190.   maps URLs to directories and files within your 'DocumentRoot'.  You
  191.   must specify the name of a file within your DocumentRoot directory,
  192.   but that file need not (and probably should not) actually exist.
  193.   When Apache tries to serve that file, it will instead send the
  194.   request through FastCGI.  Make sense?
  195.  
  196.   Say, for instance, you want zope to be accessible from this URL:
  197.  
  198.     http://myserver.org/myzope
  199.  
  200.   Suppose further that you have Apache installed at /usr/local/apache.
  201.   The directive would have to look like this::
  202.  
  203. FastCgiExternalServer /usr/local/apache/htdocs/myzope \
  204.                       ...
  205.                       ...
  206.  
  207.   The next argument depends on whether you are using a TCP port or a
  208.   socket.  Note that the -host (port) argument requires the hostname.
  209.   In the example, it's the same host as Apache runs on, but this need
  210.   not be the case.  If you are using a socket, make sure Apache has
  211.   the appropriate privileges to find it.
  212.  
  213.   The last argument, '-pass-header Authorization', tells FastCGI to
  214.   pass the Authorization headers to Zope.  Without this, you would not
  215.   be able to use the Zope web management interface, or anything else
  216.   that requires authorization.  (Note: This feature was not in
  217.   mod_fastcgi 2.2.2)
  218.  
  219.   One more item must be added to the httpd.conf.  Below the
  220.   'FastCgiExternServer' directive, enter the following::
  221.  
  222. <Location /zope>
  223.  SetHandler fastcgi-script
  224. </Location>
  225.  
  226.   ...changing '/zope' as appropriate.  Using the
  227.   'http://myserver.org/myzope' example from above, it would look like
  228.   this::
  229.  
  230. <Location /myzope>
  231.  SetHandler fastcgi-script
  232. </Location>
  233.  
  234.   This creates a special case for the location specified, telling
  235.   Apache to let FastCGI handle the request.
  236.  
  237.   That is all that is needed.  Make sure Zope is running, start or
  238.   restart Apache, and you are finished.
  239.  
  240.  
  241. Using Zope in single-threaded mode with pcgi_publisher
  242. ------------------------------------------------------
  243.  
  244.   The installation process should create a 'Zope.cgi' PCGI file. Copy the
  245.   'Zope.cgi' file to your web server's cgi-bin directory.
  246.   
  247.   On Unix you can also create a symbolic link to 'Zope.cgi' from your cgi-bin
  248.   directory. For example::
  249.  
  250.     ln -s /home/amos/Zope/Zope.cgi /usr/local/apache/cgi-bin/Zope
  251.  
  252.   At this point you should perform any other steps you web server
  253.   requires to install and configure a CGI script.
  254.  
  255.   Note: For more information on PCGI check out Jeff Bauer's "PCGI pages", 
  256.   http://starship.skyport.net/crew/jbauer/persistcgi/.
  257.  
  258.   When your Zope.cgi file is correctly configured as a CGI script with
  259.   your web server, you are ready to access Zope through the web. You
  260.   should point your browser at:
  261.  
  262.     'http://youmachine.example.com:8998/cgi-bin/Zope.cgi/manage'
  263.  
  264.   (Your URL maybe be different depending on how your web server is
  265.   configured.)
  266.  
  267.   You should be prompted to enter a username and password. Enter the Zope
  268.   "super manager" name and password.
  269.  
  270. Zope authentication with existing web servers
  271. ---------------------------------------------
  272.  
  273.   Zope normally performs both authentication and authorization of
  274.   users.  Some web servers don't pass authentication information to
  275.   CGI scripts.  If you keep getting rejected when you try to access
  276.   Zope through the web with the "super manager" user name and
  277.   password, there is a good chance that your web server is not passing
  278.   authentication information to Zope.
  279.  
  280.   Getting Apache to pass authentication headers
  281.  
  282.     Before attempting to use your own Apache with Zope, it is highly
  283.     recommended that you look at Zap.  Zap is a preconfigured and
  284.     precompiled version of Apache for Linux that drops right into Zope
  285.     with no hassles.  Even if you want to use your own Apache, or if
  286.     you use it on a different platform than Linux, it is very helpful
  287.     to have Zap's 'httpd.conf' file to guide you through configuring
  288.     Apache.
  289.  
  290.     Zap can be found on the Zope website at:
  291.  
  292.       http://www.zope.org/Download/Releases/Zap-1.1.0
  293.  
  294.     If you are using Apache you will need to convince Apache to pass
  295.     authentication headers to Zope. The easiest way to do this with
  296.     Apache 1.3 and above is to use mod_rewrite. Here is an example of
  297.     configuration information which you would place in an Apache conf
  298.     file::
  299.  
  300.       # Zope configuration maps /Zope/ to the Zope.cgi CGI script
  301.       RewriteEngine on
  302.       RewriteCond %{HTTP:Authorization}  ^(.*)
  303.       RewriteRule ^/Zope(.*) /usr/local/apache/cgi-bin/Zope.cgi/$1 [e=HTTP_CGI_AUTHORIZATION:%1,t=application/x-httpd-cgi,l]
  304.  
  305.     Note that the RewriteRule should be one long line, and that the last
  306.     character is the letter l, not the number 1.
  307.  
  308.     For Apache servers version 1.3b4 and above, there is an alternate way 
  309.     to get the server to pass through authorization headers, but you must
  310.     have the ability to recompile your Apache server binary. If you pass
  311.     the flag -DSECURITY_HOLE_PASS_AUTHORIZATION when compiling the server,
  312.     the resulting Apache binary will allow authorization headers to pass
  313.     through to CGI programs and you can avoid using the Rewrite rules
  314.     described above.
  315.  
  316.  
  317.   Allowing your server to handle authentication itself
  318.  
  319.     Sometimes you may prefer to handle authentication outside Zope, for
  320.     example if your web server already does complex authorization, or
  321.     if it seems too difficult to convince it to pass authentication
  322.     information to Zope.
  323.  
  324.     As of 1.9, Zope began supporting a mode that allowed the web
  325.     server to handle authentication.  The 'REMOTE_USER' environment
  326.     variable is then matched to the identity of a user object in Zope.
  327.  
  328.     The following provide step-by-step instructions for setting this
  329.     up in Apache, allowing both the Zope "super manager" defined in
  330.     the Zope 'access' file and users defined in Zope User Folders to
  331.     be authenticated via the web server.
  332.  
  333.       Get Apache to authenticate /cgi-bin/Zope
  334.  
  335.         Add a directive in your Apache configuration file such as::
  336.  
  337.          <Location /cgi-bin/Zope/>
  338.          AuthType Basic
  339.          AuthName Zope-realm
  340.          AuthUserFile /usr/local/etc/httpd/conf/ru_users
  341.          require valid-user
  342.          </Location>
  343.  
  344.         Then send Apache a '-1' signal to tell it to re-read its
  345.         configuration files.
  346.  
  347.         *Note*: The above presumes that '/cgi-bin/Zope' has been made
  348.         executable by some other Apache directive in the configuration
  349.         file.
  350.  
  351.       Ensure Apache has 'superuser'
  352.  
  353.         Using Apache's tools for managing a user database, make 
  354.         sure that the 'AuthUserFile' defined above has a valid user 
  355.         called 'superuser'.
  356.  
  357.       Get Zope to use Apache's authentication
  358.  
  359.         Change Zope's access file to contain just the superuser
  360.         id followed by a colon, as in::
  361.  
  362.           superuser:
  363.  
  364.         Note that this can be any value, including spaces.  The only
  365.         restriction is that the value must match a user defined in
  366.         Apache's user database.
  367.  
  368.         N.B.:  removing the password in the access file also enables
  369.                access to the monitor for any user connecting through
  370.                the localhost interface -- DISABLE THE MONITOR if using
  371.                this option on any box which allows untrusted logins.
  372.  
  373.         Shut down Zope by doing::
  374.  
  375.           kill `cat var/Main.pid`
  376.  
  377.         from the Zope directory.
  378.  
  379.       Configure Zope
  380.  
  381.         At this point you are able to log in using the "superuser"
  382.         identity.  If you want other people defined in the Apache user
  383.         database to have identities in Zope, you need to add them to
  384.         a User Folder (the object whose ID is acl_users). Either click on
  385.         the pre-defined acl_users in the top folder or add a User Folder
  386.         object to a subfolder.
  387.   
  388.   Specific web servers
  389.   
  390.     Apache
  391.     
  392.       * As mentioned above, Apache does not pass authorization
  393.       information to CGI scripts by default. See above for information
  394.       on how to deal with this situation.
  395.  
  396.       * An Apache module to support PCGI (mod_pcgi) is under
  397.         development.
  398.  
  399.     Netscape Servers
  400.   
  401.       * Like Apache, Netscape does not pass HTTP Authorization
  402.       information to CGI scripts.  We have a plugin at our website
  403.       that addresses this.  http://www.digicool.com
  404.   
  405.       * Alternatively, you can allow the web server to perform the
  406.       authentication step. See above for more information.
  407.       
  408.     IIS
  409.   
  410.       * You must turn off Windows NT Challenge/Response
  411.       authentication.  To do this, go to IIS Manager, right-click on
  412.       the server, select Service Properties, and deselect *both*
  413.       'Windows NT Challenge/Response' and, strangely, Basic
  414.       Authentication from the Password Authentication area of the
  415.       Service tabbed worksheet.
  416.   
  417.       * IIS kindly throws out PATH_INFO when writing to its logs, so if
  418.       you want to log which Zope objects are actually being
  419.       accessed, you will need to investigate an ISAPI filter
  420.  
  421.       * An ISAPI module to support PCGI is under development.
  422.  
  423.       * IIS 4.0 throws away Zope's error messages by default. This 
  424.         behavior can create quite a few problems, including authentication 
  425.         problems.
  426.  
  427.       Microsoft prides itself on the clear error messages that IIS 4.0 
  428.       presents, when the user makes a mistake. These error messages are 
  429.       implemented in the form of Custom Error handlers, that return a file, 
  430.       or URL to a user when a certain error occurs.
  431.  
  432.       This means, that when you forget to fill in an Id when you want to 
  433.       create, say, a new SQL Method, Zope's clear error message is replaced 
  434.       by IIS's totally irrelevant error message. Also, it completely breaks 
  435.       authentication when the user uses IE5.0 when trying to log into a secure 
  436.       area of the server. These Custom Error handlers are enabled by default.
  437.  
  438.       Luckily, the handlers can quite easily be switched off:
  439.  
  440.       Open the IIS website in the Management Console, and navigate to the 
  441.       folder you put the PCGI executable in. If you named your Zope installation 
  442.       'Zope', it will be called 'Zope.exe'. Double-click on that file. A property 
  443.       page will appear. Select the 'Custom Errors' tab. Now, select every HTTP 
  444.       Error code in the listbox that doesn't have type 'Default', and click on 
  445.       the 'Set to Default' button for each one. This will disable IIS overriding 
  446.       the error message returned by Zope.
  447.  
  448.       Click OK, and voila, Zope is allowed to tell the world what it thinks went
  449.       wrong.
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.